package com.ljsw.dialog;

import com.ljsw.activity.R;
import com.ljsw.view.MyProgressBar;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

/**
* @Package com.ljsw.dialog 
* @Description: TODO(进度条提示框) 
* @author 郑鸿博   
* @date 2015-11-27 上午9:10:31 
* @version V1.0
 */
public class ProgressBarDialog {
	
	public ProgressBarDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();//获取屏幕分辨率
	}
	
	private Context context;
	private Display display;
	private Dialog dialog; 
	private TextView barTitle;
	private MyProgressBar bar;
//	private ProgressBar bar;
	private LinearLayout layout_bar;
	
	public ProgressBarDialog builder(){
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_progressbar, null);
		layout_bar = (LinearLayout) view.findViewById(R.id.layout_bar);
		barTitle = (TextView) view.findViewById(R.id.bar_title);
		bar = (MyProgressBar) view.findViewById(R.id.bar);
	//	bar = (ProgressBar) view.findViewById(R.id.progressBar1);
		bar.setMax(100);
		// 添加Dialog样式
		dialog = new Dialog(context, R.style.LoginDialog);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域不关闭Dialog
		// 调整dialog背景大小
		layout_bar.setLayoutParams(new FrameLayout.LayoutParams(
				(int) (display.getWidth() * 0.85), LayoutParams.WRAP_CONTENT));
		return this;
	}
	/**
	 * 设置标题
	 * @param title
	 * @return
	 */
	public ProgressBarDialog setTitle(String title){
		barTitle.setText(title);
		return this;
	}
	
	/**
	 * 设置进度显示
	 * @param progress
	 * @return
	 */
	public ProgressBarDialog setProgress(int progress){
		
		bar.setProgress(progress); 
		return this;
	}
	
	public void show(){
		dialog.show();
	}
	
	public void dismiss(){
		dialog.dismiss();
	}
	
}
